<include file="Public/head" />
<include file="Public/common_header" />
<script src="http://img1.isou365.cn/paimai/yunying/js/global.js"></script>
<div class="mian">
    <include file="Public/sidebar" menu="cwgl.yjgl"  />
    <div class="mianR">
        <h3 class="yonghu">红包发放管理</h3>
        <div class="yuyue">
            <ul>
                <li class="yuCurrent">累积</li>
                <li>未提取</li>
                <li>提取中</li>
                <li>提取成功</li>
                <li>提取失败</li>
            </ul>
        </div>
        <div class="listBox">
            <div class="yuList">

            </div>
        </div>
        <div class="clear"></div>
    </div>
</div>
<script>

    function batch_withdraw () {
        if(!confirm("确认批量提现?")){
            return false;
        }
        var ids = [];
        $("input[name='check_row']:checked").each(function () {
            ids.push($(this).val());
        });
        if(ids.length<1){
            shibai_alert("请选择一条记录");
        }
        $.post('/RedPackets/batchWithdraw',{ids:ids},function (data) {
            if(data.code!=200){
                shibai_alert(data.msg,1000);
                return false;
            }
            btn_alert('操作成功',1000,function () {
                window.location.reload();
            });
        },'json');
    }

    var RedPacket=(function(){

        function _post(post_data){
            var t = post_data.t;
            var url = (post_data.url==undefined?'/RedPackets/getList':post_data.url);
            $.get(url,post_data,function(data){
                $('.listBox .yuList').html(data);
                $("input").placeholder();
                $("#start_time").ymdateplugin({
                    changeMonth: true,
                    changeYear: true
                });

                $("#end_time").ymdateplugin({
                    changeMonth: true,
                    changeYear: true
                });

                $("#check_all").click(function(event) {
                    var $that = $(this);
                    $("tbody input[type='checkbox']").each(function(index, el) {
                        $(el).prop('checked', $that.prop('checked'));
                    });
                });
            });
        }

        function _init(){

            $('.yuyue li').click(function(){
                var t = $(this).index();
                if(t>1){
                    _post({url:'/RedPackets/withdrawList',t:t});
                }else{
                    _post({t:t});
                }
            });

            _post({t:0})

        }

        _init();
        
        function _get_withdraw_list(t,p,uid,mobile,real_name,id_card,stime,etime) {
            _post({
                url:'/RedPackets/withdrawList',
                t: t,
                p: p,
                uid: uid,
                mobile: mobile,
                real_name : real_name,
                id_card : id_card,
                start_time:stime,
                end_time:etime
            });
        }

        function _get(t,p,u,m){
            _post({t: t, p: p, uid: u, mobile: m});
        }

        function _search(t, p) {
            if (t < 2) {
                var u = $("#uid").val();
                var m = $("#phone").val();
                _get(t, p, u, m);
            } else {
                var u = $("#uid").val();
                var m = $("#phone").val();
                var real_name = $("#real_name").val();
                var id_card = $("#id_card").val();
                var stime = $("#start_time").val();
                var etime = $("#end_time").val();
                _get_withdraw_list(t, p, u, m, real_name, id_card, stime, etime);
            }
        }
        
        function paging(p) {
            var t = $("#t").val();
            _search(t,p);
        }

        return {get:_get,get_wl:_get_withdraw_list,s:_search,p:paging}
    })();
</script>
<include file="Public/foot" />